package com.woniuxy.microsportsserver.walkmag.mapper;

import com.woniuxy.microsportsserver.bean.WalkAnalysisInfo;
import com.woniuxy.microsportsserver.bean.WalkInfo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface WalkMapper {
   /* @ResultType(HashMap.class)
    @Select("select s.stall_name as stallName,s.stall_area as stallArea,a.start_time as startTime,a.end_time as endTime,a.earnest_money as earnestMoney" +
            " from auction_info as a,stall_info as s where a.fk_stall_id = s.id" +
            " and a.auction_status = 1")
    List<HashMap> findAll();*/
//    SELECT COUNT(walk_num) AS walkTotalNum,COUNT(walk_dura) AS walkTotalDura,COUNT(walk_length) AS walkTotalLength,
//COUNT(walk_consume) AS walkTotalConsume,user_id AS userId,user_name AS userName FROM walk_info GROUP BY user_id

    /*@Select("select count(walk_num) as walkTotalNum,count(walk_dura) as walkTotalDura, " +
            "count(walk_length) as walkTotalLength,count(energy_consume) as walkTotalConsume " +
            "user_id as userId,user_name as userName from walk_info group by user_id")*/
    List<WalkInfo> findAll(@Param("w")WalkInfo walkInfo);

   /**
    * 根据userid 查询走步明细
    * @param walkInfo
    * @return
    */
 //   @Select("select walk_num as walkNum,walk_dura as walkDura,walk_length as walkLength,energy_consume")
    List<WalkInfo> findRecordsByUserId(@Param("w")WalkInfo walkInfo);
    //走步平均数
    List<WalkAnalysisInfo> findNumAvgBytimeType();

    //走步前十名
    //周
    @Select("select user_name as userName,sum(walk_num) as walkTotalNum " +
            "from user_walk_info where YEARWEEK(DATE_FORMAT(time,'%Y-%m-%d')) = YEARWEEK(NOW())" +
            " group by user_id ORDER BY walkTotalNum DESC LIMIT 0,6")
    List<WalkAnalysisInfo> findTop10ByTimeType1 (@Param("wa")WalkAnalysisInfo walkAnalysisInfo);

    //月
    @Select("select user_name as userName,sum(walk_num) as walkTotalNum " +
            "from user_walk_info where DATE_FORMAT(time,'%Y%m') = DATE_FORMAT(CURDATE(),'%Y%m')" +
            " group by user_id ORDER BY walkTotalNum DESC LIMIT 0,2")
    List<WalkAnalysisInfo> findTop10ByTimeType2 (@Param("wa")WalkAnalysisInfo walkAnalysisInfo);

    //年
    @Select("select user_name as userName,sum(walk_num) as walkTotalNum " +
            "from user_walk_info where YEAR(time)=YEAR(NOW())" +
            " group by user_id ORDER BY walkTotalNum DESC LIMIT 0,5")
    List<WalkAnalysisInfo> findTop10ByTimeType3 (@Param("wa")WalkAnalysisInfo walkAnalysisInfo);


    //走路年龄占比
    List<WalkAnalysisInfo> findWalkPercentageBYUser();


}
